from deslab import *




#
#a,b,c,d,e,sf,x0,x1,x2,x3,x4,x5,x6,x7 = definesymbols('a b c d e \sigma_f 0 1 2 3 4 5 6 7')
#a,b,c,d,e,sf,x0,x1,x2,x3,x4,x5,x6,x7 = definesymbols('a b c d e \sigma_f 0 1 2 3 4 5 6 7')
#
#sigma=set([a,b,c,d,e,sf])
#sigmaf=set([sf])
#X=[x1,x2,x3,x4,x5,x6,x7]
#X0=[x1]
#Xm=[x1,x7]
#transicoes=[[x1,c,x2],[x1,a,x5],[x2,sf,x3],[x3,e,x4],
#            [x4,d,x4],[x1,a,x5],[x5,b,x6],[x6,d,x6],[x7,e,x7],[x3,a,x7]]
#sigmaobs=[a,b,c,d]
#G=fsa(X,sigma,transicoes,X0,Xm,Eobs=sigmaobs,name='$G$') 
#D=diagnoser(G,sf,sigmaobs)



## exemplo 3 I think this is the final example
a,b,c,d,e,sf,g,x0,x1,x2,x3,x4,x5,x6,x7 = syms('a b c d e sf g 0 1 2 3 4 5 6 7')
sigma=set([a,b,c,d,e,sf])
sigmaf=set([sf])
X=[x1,x2,x3,x4,x5,x6,x7]
X0=[x1]
Xm=[x1,x7]
transicoes=[[x1,c,x2],[x1,a,x5],[x2,sf,x3],[x3,e,x4],[x4,a,x1],[x6,a,x1],[x6,e,x3],[x7,b,x1],
            [x4,d,x4],[x1,a,x5],[x5,b,x6],[x6,d,x6],[x7,d,x7],[x3,a,x7]]
sigmaobs=[a,c,d,e]
G=fsa(X,sigma,transicoes,X0,Xm,name='G') 
draw(G)


def dilatation(G,Sigmaisf):
    GA = G 
    for state in G.X:
        for event in (G.gamma(state) & set(Sigmaisf)):
            next_state = G.delta(state,event)
            event_uo = event + "'"
            GA = GA.addtransition([state,event_uo,next_state])   
    Gisf = observer(GA,G.E)
    Gisf.Eobs = G.Eobs
    Gisf.name = '$G_{isf}$ -- intermitent failure model'          
    return Gisf
             
G.name='$G$ -- nominal model'
Sigmaisf = [a]
Gisf=dilatation(G,Sigmaisf)
Gisf.direction='LR'
draw(G,Gisf)


